﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Model;

namespace DAL
{
    /// <summary>
    /// 管理员数据访问类
    /// </summary>
    public class SysAdminService
    {
        public SysAdmin AdminLogin(SysAdmin admin)
        {
            var sql = "select LoginId,AdminName,LoginPwd from Admins where AdminName='{0}' and LoginPwd='{1}'";
            sql = string.Format(sql, admin.AdminName, admin.LoginPwd);
            try
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(sql);
                if (reader.Read())
                {
                    admin.LoginId = Convert.ToInt32(reader["LoginId"]);
                    admin.AdminName = reader["AdminName"].ToString();
                    admin.LoginPwd = reader["LoginPwd"].ToString();
                }
                else
                {
                    admin = null;
                }
                reader.Close();
                return admin;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

    }
}
